package org.jimmy.tang.array;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author jimmy
 * 
 */
public class ArrayToSet {

    public static void main(String... arg) {
        Employee1 jim = new Employee1("Jim");
        Employee1 bob = new Employee1("Bob");
        Employee1 gin = new Employee1("Gin");

        /************ Set to Array ********************************/
        Set<Employee1> staff = new HashSet<Employee1>();
        staff.add(jim);
        staff.add(bob);
        staff.add(gin);
        System.out.println(staff);// [Name:Jim, Name:Bob, Name:Gin]

        Employee1[] e = new Employee1[staff.size()];
        staff.toArray(e);
        for (Employee1 em : e) {
            System.out.println(em);
            /* 
             * Name:Jim 
             * Name:Bob 
             * Name:Gin 
             * */
        }

        /************ Array to Set ********************************/
        List<Employee1> arrayToList = Arrays.asList(e);
        System.out.println(arrayToList.get(2));// Name:Gin

    }
}

class Employee1 {
    public Employee1(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "Name:" + name;
    }

    private String name = "";// 实例域初始化
}